package com.aigis.big4.tmp.javase.thread.queue;

public class PublicBox {
    private int total = 0;

    public synchronized void increase() {
        while (total == 5) {
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        total++;
        System.out.println("create一个");
        notify();
    }

    public synchronized void decrease() {
        while (total == 0) {
            try{
                wait();
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
        total--;
        System.out.println("消费一个");
        notify();
    }

    public static void main(String[] args) {
        PublicBox box = new PublicBox();
        Producer producer = new Producer(box);
        Consumer consumer = new Consumer(box);
        Thread t1=new Thread(producer);

        Thread t2=new Thread(consumer);
        t1.start();
        t2.start();
    }

}
